# ============= 导入模块 ==============
from django_filters import FilterSet, filters
from studentweb.models import Faculty, Major, Student


# --- Faculty的Filter类 ---
class FacultyFilter(FilterSet):
    # 重新需要支持模糊匹配的字段
    name = filters.CharFilter(field_name='name', lookup_expr="icontains")

    class Meta:
        model = Faculty
        fields = ('name', )


# --- Major的Filter类 ---
class MajorFilter(FilterSet):
    # 重新需要支持模糊匹配的字段
    name = filters.CharFilter(field_name='name', lookup_expr="icontains")

    class Meta:
        model = Major
        fields = ('name', 'faculty')


# --- Student的Filter类 ---
class StudentFilter(FilterSet):
    sno = filters.CharFilter(field_name='sno', lookup_expr="icontains")
    name = filters.CharFilter(field_name='name', lookup_expr="icontains")
    mobile = filters.CharFilter(field_name='mobile', lookup_expr="icontains")
    major = filters.CharFilter(field_name='major')
    faculty = filters.CharFilter(field_name='major__faculty')

    class Meta:
        model = Student
        fields = ('sno', 'name', 'mobile', 'major')
